//import 'package:amap_base/amap_base.dart';

import 'dart:async';
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hotwork/HomePage.dart';
import 'package:flutter_hotwork/bean/messagebean.dart';
import 'package:flutter_hotwork/homepage/BaseTitleBar.dart';
import 'package:flutter_hotwork/homepage/BaseViewBar.dart';
import 'package:flutter_hotwork/utils/DioUtils.dart';
import 'package:flutter_hotwork/zhifa/QuestionListBean.dart';
import 'package:fluttertoast/fluttertoast.dart';
// import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'Toast.dart';


class IPConfigPage extends StatefulWidget {
  @override
  IPConfigState createState() => new IPConfigState();
}
messagebean messagelist;
bool hasdata = false;
class IPConfigState extends State<IPConfigPage> {
  TextEditingController ipController = TextEditingController();
  @override
  void initState() {
    super.initState();
    DioUtils.createInstance();
  }

  @override
  void dispose() {
//    _amapLocation.stopLocate();
    super.dispose();
  }
  TabController _tabController;

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: new BaseViewBar(
          childView: new BaseTitleBar(
            "地址设置",
            leftIcon: 'images/fanhui.png',
            rightIcon:  '',
            rightClick: () {
            },
            leftClick: () {
              print("点击了左边干嘛啊。。。哦");
              Navigator.of(context).pop();
            },
          ),
          preferredSize: Size.fromHeight(50.0)),

      body:

      Container(
        child:
        Column(
          children: [
            Container(
              height: 30,
              margin: EdgeInsets.only(left: 0, right: 0, top:20, bottom: 20),
              padding:  EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
              decoration: BoxDecoration(
                border: new Border.all(color: Color(0xFF9E9E9E), width: 0.5), // 边色与边宽度
                color: Colors.white, // 底色
                //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                borderRadius: BorderRadius.all(Radius.circular(15)),
              ),
              child:
              TextField(

                style: TextStyle(color: Colors.grey),
                // controller: passController..text="Jjrd2020!@#",
                controller: ipController..text=DioUtils.API_PREFIX,
                decoration: InputDecoration(
                  contentPadding: EdgeInsets.all(8.0),
                  hintText: '请输入新的ip地址',
                  hintStyle: TextStyle(color: Colors.grey),
                  border:InputBorder.none,
                ),
                autofocus: false,
              ),

            ),

            ButtonTheme(
              minWidth: 200.0,//设置最小宽度
              height: 30.0,
              child: RaisedButton(
                onPressed:(){
                  setUserName(ipController.text);
                } ,
                child: Text('保存',style: new TextStyle(color: Colors.white),
                ),
                color:Colors.blue,
                shape:RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(15)),
                ),
              ),
            ),
          ],
        ),
      )
    );
  }
  setUserName(String address) async{
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setString("ip",address);
    DioUtils.API_PREFIX = address;
    LocalToast.toast(context,msg:"保存成功！");

  }

   getIPAddress() async{
    SharedPreferences prefs = await SharedPreferences.getInstance();
    if(prefs.containsKey("ip")){
      ipController..text = prefs.getString("ip");
    }
  }

}






















